package com.dzm.demo.myshop.web.ui.api;

import com.dzm.demo.myshop.commons.dto.BaseResult;
import com.dzm.demo.myshop.commons.utils.HttpClientUtils;
import com.dzm.demo.myshop.commons.utils.MapperUtils;
import com.dzm.demo.myshop.web.ui.dto.TbContent;
import com.dzm.demo.myshop.web.ui.dto.TbUser;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * 会员管理接口
 *@author:LeoDang
 *@date:2019/7/22
 *@version 1.0.0
 */
public class UserApi {

    /**
     * 登陆
     * @param tbUser
     * @return
     */
    public static TbUser login(TbUser tbUser) throws Exception {
        List<BasicNameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("username",tbUser.getUsername()));
        params.add(new BasicNameValuePair("password",tbUser.getPassword()));

        String json = HttpClientUtils.doPost(API.API_USER_LOGIN,params.toArray(new BasicNameValuePair[params.size()]));
        TbUser user = MapperUtils.json2pojoByTree(json,"data",TbUser.class);
        return user;
    }
}
